<!--
 * @Author: C.
 * @Date: 2021-07-12 19:42:41
 * @LastEditTime: 2021-08-25 09:24:07
 * @Description: file content
-->
<template>
  <BasicTable
    @register="registerTable"
    :rowSelection="{ type: 'checkbox', selectedRowKeys: checkedKeys, onChange: onSelectChange }"
  >
    <template #form-custom> custom-slot </template>
    <template #headerTop>
      <a-alert type="info" show-icon>
        <template #message>
          <template v-if="checkedKeys.length > 0">
            <span>已选中{{ checkedKeys.length }}条记录(可跨页)</span>
            <a-button type="link" @click="checkedKeys = []" size="small">清空</a-button>
          </template>
          <template v-else>
            <span>未选中任何项目</span>
          </template>
        </template>
      </a-alert>
    </template>

<template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '删除',
              icon: 'ic:outline-delete-outline',
            
              popConfirm: {
                title: '是否删除？',
                confirm: handleOpen.bind(null, record),
              },
            },
          ]"
          :dropDownActions="[
            {
              label: '启用',
              popConfirm: {
                title: '是否启用？',
                confirm: handleOpen.bind(null, record),
              },
            },
          ]"
        />
      </template>


    <template #toolbar>
      <a-button type="primary" @click="getFormValues">获取表单数据</a-button>
      <a-button type="primary" @click="createNewBill">新增单据</a-button>
    </template>
  </BasicTable>
</template>
<script lang="ts">
  import { defineComponent, ref } from 'vue';
  import { BasicTable, useTable,TableAction } from '/@/components/Table';
  import { getBasicColumns, getFormConfig } from './data';
  import { Alert, } from 'ant-design-vue';
  import { testApi } from '/@/api/sys/test';
  import { router } from '/@/router';

  export default defineComponent({
    components: { BasicTable, AAlert: Alert,TableAction },
    setup() {
      const checkedKeys = ref<Array<string | number>>([]);
      const [registerTable, { getForm }] = useTable({
        title: '开启搜索区域',
        api: testApi,
        columns: getBasicColumns(),
        useSearchForm: true,
        formConfig: getFormConfig(),
        showTableSetting: true,
        tableSetting: { fullScreen: true },
        showIndexColumn: true,
        rowKey: 'BillId',
        ellipsis:true,
        actionColumn: {
          width: 160,
          title: 'Action',
          dataIndex: 'action',
          slots: { customRender: 'action' },
        },
      });

      function getFormValues() {
        console.log(getForm().getFieldsValue());
      }

      function onSelectChange(selectedRowKeys: (string | number)[]) {
        console.log(selectedRowKeys);
        checkedKeys.value = selectedRowKeys;
      }
      function handleOpen(e){
        console.log(e,123);
        
      }
     function createNewBill(){
       router.push({name:'test3'})
      }
      return {
        registerTable,
        getFormValues,
        checkedKeys,
        onSelectChange,
        handleOpen,
        createNewBill
      };
    },
  });
</script>
